//
//  WXPOrderDeferDetailHeaderView.m
//  MexicoLoan
//
//  Created by wxp on 2025/3/18.
//

#import "WXPOrderDeferDetailHeaderView.h"

@implementation WXPOrderDeferDetailHeaderView

#pragma mark - lazy
- (WXPOrderDetailTopMoneyView *)topMoneyView{
    if (!_topMoneyView) {
        _topMoneyView = [WXPOrderDetailTopMoneyView new];
    }
    return _topMoneyView;
}
- (UIButton *)btnRostpone{
    if (!_btnRostpone) {
        _btnRostpone = [UIButton new];
        _btnRostpone.widthHeight = XY(SCREEN_WIDTH-LEFT_MARDIN*2, BUTTON_HEIGHT);
        [GlobalMethod setRoundView:_btnRostpone color:[UIColor clearColor] numRound:BUTTON_HEIGHT/2 width:0];
        [_btnRostpone setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnRostpone.titleLabel.fontNum = 14;
        [_btnRostpone setTitle:@"Confirmar la prórroga de periodo" forState:UIControlStateNormal];
        _btnRostpone.backgroundColor = COLOR_PRIMARY;
        _btnRostpone.tag = 1;
        [_btnRostpone addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnRostpone;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, 0);
        self.backgroundColor = [UIColor clearColor];
        [self addSubView];
    }
    return self;
}

- (void)addSubView{
    [self addSubview:self.topMoneyView];
    [self addSubview:self.btnRostpone];
    [self resetViewOrderModel:nil deferModel:nil];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1: // 延期
        {
            if(self.blockDeferRepayment){
                self.blockDeferRepayment();
            }
        }
            break;
        default:
            break;
    }
}

#pragma mark - 刷新View
- (void)resetViewOrderModel:(ModelOrderDetail *)model deferModel:(ModelPostpone *)modelPostpone{
    [self.topMoneyView resetViewWithModelOrderDetail:model modelPostpone:modelPostpone];
    self.topMoneyView.centerXTop = XY(self.width/2, 0);
    
    self.btnRostpone.centerXTop = XY(self.width/2, self.topMoneyView.bottom+LEFT_MARDIN);
    self.height = self.btnRostpone.bottom+LEFT_MARDIN;
}


@end
